﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exhibition.Common.Helper
{
    public class LogHelper
    {
        private static string DefaultName = "log";
        static LogHelper()
        {
            //string path = @"C:\ConsoleApplication1\ConsoleApplication1\log.config";
            //string path = System.Web.HttpContext.Current.Server.MapPath(@"~\Log\Error.log");
            //log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
        }

        public static log4net.ILog GetLog(string logName)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(logName);
            return log;
        }
        public static void Debug(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsDebugEnabled)
            {
                log.Debug(message);
            }
            log = null;
        }
        public static void Debug(string message, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsDebugEnabled)
            {
                log.Debug(message, ex);
            }
            log = null;
        }
        public static void Error(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsErrorEnabled)
            {
                log.Error(message);
            }
            log = null;
        }
        public static void Error(string message, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsErrorEnabled)
            {
                log.Error(message, ex);
            }
            log = null;
        }
        public static void Fatal(string message)
        {

            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsFatalEnabled)
            {
                log.Fatal(message);
            }
            log = null;
        }
        public static void Info(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsInfoEnabled)
            {
                log.Info(message);
            }
            log = null;
        }

        public static void Warn(string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(DefaultName);
            if (log.IsWarnEnabled)
            {
                log.Warn(message);
            }
            log = null;
        }

    }
}
